class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        ListNode* guard = new ListNode;
        guard->next = head;
        ListNode* fast = guard;
        ListNode* slow = guard;
        ++n;
        while (n--) fast = fast->next;
        while (fast)
        {
            fast = fast->next;
            slow = slow->next;
        }
        ListNode* del = slow->next;
        slow->next = del->next;
        delete del;
        head = guard->next;
        delete guard;
        return head;
    }
};